home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gstext.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  11.4 KB  |  310 lines

  1. /* Copyright (C) 1998, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gstext.h,v 1.3 2000/09/19 19:00:32 lpd Exp $ */
  20. /* Driver interface for text */
  21.  
  22. #ifndef gstext_INCLUDED
  23. #  define gstext_INCLUDED
  24.  
  25. #include "gsccode.h"
  26. #include "gscpm.h"
  27.  
  28. /*
  29.  * Note that text display must return information to the generic code:
  30.  *    If TEXT_RETURN_WIDTH or TEXT_DO_CHARWIDTH, the string escapement
  31.  *      (a.k.a. "width");
  32.  *    If TEXT_DO_*_CHARPATH, the entire character description;
  33.  *    If TEXT_DO_*_CHARBOXPATH, the character bounding box.
  34.  */
  35.  
  36. /*
  37.  * Define the set of possible text operations.  While we define this as
  38.  * a bit mask for convenience in testing, only certain combinations are
  39.  * meaningful.  Specifically, the following are errors:
  40.  *      - No FROM or DO.
  41.  *      - More than one FROM or DO.
  42.  *    - FROM_SINGLE with size != 1.
  43.  *      - Both ADD_TO and REPLACE.
  44.  */
  45. #define TEXT_HAS_MORE_THAN_ONE_(op, any)\
  46.   ( ((op) & any) & (((op) & any) - 1) )
  47. #define TEXT_OPERATION_IS_INVALID(op)\
  48.   (!((op) & TEXT_FROM_ANY) ||\
  49.    !((op) & TEXT_DO_ANY) ||\
  50.    TEXT_HAS_MORE_THAN_ONE_(op, TEXT_FROM_ANY) ||\
  51.    TEXT_HAS_MORE_THAN_ONE_(op, TEXT_DO_ANY) ||\
  52.    (((op) & TEXT_ADD_ANY) && ((op) & TEXT_REPLACE_WIDTHS))\
  53.    )
  54. #define TEXT_PARAMS_ARE_INVALID(params)\
  55.   (TEXT_OPERATION_IS_INVALID((params)->operation) ||\
  56.    ( ((params)->operation & TEXT_FROM_ANY_SINGLE) && ((params)->size != 1) )\
  57.    )
  58.  
  59.     /* Define the representation of the text itself. */
  60. #define TEXT_FROM_STRING          0x00001
  61. #define TEXT_FROM_BYTES           0x00002
  62. #define TEXT_FROM_CHARS           0x00004
  63. #define TEXT_FROM_GLYPHS          0x00008
  64. #define TEXT_FROM_SINGLE_CHAR     0x00010
  65. #define TEXT_FROM_SINGLE_GLYPH    0x00020
  66. #define TEXT_FROM_ANY_SINGLE    /* only for testing and masking */\
  67.   (TEXT_FROM_SINGLE_CHAR | TEXT_FROM_SINGLE_GLYPH)
  68. #define TEXT_FROM_ANY    /* only for testing and masking */\
  69.   (TEXT_FROM_STRING | TEXT_FROM_BYTES | TEXT_FROM_CHARS | TEXT_FROM_GLYPHS |\
  70.    TEXT_FROM_ANY_SINGLE)
  71.     /* Define how to compute escapements. */
  72. #define TEXT_ADD_TO_ALL_WIDTHS    0x00040
  73. #define TEXT_ADD_TO_SPACE_WIDTH   0x00080
  74. #define TEXT_ADD_ANY    /* only for testing and masking */\
  75.   (TEXT_ADD_TO_ALL_WIDTHS | TEXT_ADD_TO_SPACE_WIDTH)
  76. #define TEXT_REPLACE_WIDTHS       0x00100
  77.     /* Define what result should be produced. */
  78. #define TEXT_DO_NONE              0x00200    /* stringwidth or cshow only */
  79. #define TEXT_DO_DRAW              0x00400
  80. #define TEXT_DO_CHARWIDTH         0x00800    /* rmoveto by width */
  81. #define TEXT_DO_FALSE_CHARPATH    0x01000
  82. #define TEXT_DO_TRUE_CHARPATH     0x02000
  83. #define TEXT_DO_FALSE_CHARBOXPATH 0x04000
  84. #define TEXT_DO_TRUE_CHARBOXPATH  0x08000
  85. #define TEXT_DO_ANY_CHARPATH    /* only for testing and masking */\
  86.   (TEXT_DO_CHARWIDTH | TEXT_DO_FALSE_CHARPATH | TEXT_DO_TRUE_CHARPATH |\
  87.    TEXT_DO_FALSE_CHARBOXPATH | TEXT_DO_TRUE_CHARBOXPATH)
  88. #define TEXT_DO_ANY    /* only for testing and masking */\
  89.   (TEXT_DO_NONE | TEXT_DO_DRAW | TEXT_DO_ANY_CHARPATH)
  90.     /* Define whether the client intervenes between characters. */
  91. #define TEXT_INTERVENE            0x10000
  92.     /* Define whether to return the width. */
  93. #define TEXT_RETURN_WIDTH         0x20000
  94.  
  95. /*
  96.  * Define the structure of parameters passed in for text display.
  97.  * Note that the implementation does not modify any of these; the client
  98.  * must not modify them after initialization.
  99.  */
  100. typedef struct gs_text_params_s {
  101.     /* The client must set the following in all cases. */
  102.     uint operation;        /* TEXT_xxx mask */
  103.     union sd_ {
  104.     const byte *bytes;    /* FROM_STRING, FROM_BYTES */
  105.     const gs_char *chars;    /* FROM_CHARS */
  106.     const gs_glyph *glyphs;    /* FROM_GLYPHS */
  107.     gs_char d_char;        /* FROM_SINGLE_CHAR */
  108.     gs_glyph d_glyph;    /* FROM_SINGLE_GLYPH */
  109.     } data;
  110.     uint size;            /* number of data elements, */
  111.                 /* must be 1 if FROM_SINGLE */
  112.     /* The following are used only in the indicated cases. */
  113.     gs_point delta_all;        /* ADD_TO_ALL_WIDTHS */
  114.     gs_point delta_space;    /* ADD_TO_SPACE_WIDTH */
  115.     union s_ {
  116.     gs_char s_char;        /* ADD_TO_SPACE_WIDTH & !FROM_GLYPHS */
  117.     gs_glyph s_glyph;    /* ADD_TO_SPACE_WIDTH & FROM_GLYPHS */
  118.     } space;
  119.     /* If x_widths == y_widths, widths are taken in pairs. */
  120.     /* Either one may be NULL, meaning widths = 0. */
  121.     const float *x_widths;    /* REPLACE_WIDTHS */
  122.     const float *y_widths;    /* REPLACE_WIDTHS */
  123.     uint widths_size;        /****** PROBABLY NOT NEEDED ******/
  124. } gs_text_params_t;
  125.  
  126. #define st_gs_text_params_max_ptrs 3
  127. /*extern_st(st_gs_text_params); */
  128. #define public_st_gs_text_params() /* in gstext.c */\
  129.   gs_public_st_composite(st_gs_text_params, gs_text_params_t,\
  130.     "gs_text_params", text_params_enum_ptrs, text_params_reloc_ptrs)
  131.  
  132. /* Assuming REPLACE_WIDTHS is set, return the width of the i'th character. */
  133. int gs_text_replaced_width(P3(const gs_text_params_t *text, uint index,
  134.                   gs_point *pwidth));
  135.  
  136. /*
  137.  * Define the abstract type for the structure that tracks the state of text
  138.  * processing.
  139.  */
  140. #ifndef gs_text_enum_DEFINED
  141. #  define gs_text_enum_DEFINED
  142. typedef struct gs_text_enum_s gs_text_enum_t;
  143. #endif
  144.  
  145. /* Abstract types */
  146. #ifndef gx_device_DEFINED
  147. #  define gx_device_DEFINED
  148. typedef struct gx_device_s gx_device;
  149. #endif
  150. #ifndef gs_imager_state_DEFINED
  151. #  define gs_imager_state_DEFINED
  152. typedef struct gs_imager_state_s gs_imager_state;
  153. #endif
  154. #ifndef gx_device_color_DEFINED
  155. #  define gx_device_color_DEFINED
  156. typedef struct gx_device_color_s gx_device_color;
  157. #endif
  158. #ifndef gs_font_DEFINED
  159. #  define gs_font_DEFINED
  160. typedef struct gs_font_s gs_font;
  161. #endif
  162. #ifndef gx_path_DEFINED
  163. #  define gx_path_DEFINED
  164. typedef struct gx_path_s gx_path;
  165. #endif
  166. #ifndef gx_clip_path_DEFINED
  167. #  define gx_clip_path_DEFINED
  168. typedef struct gx_clip_path_s gx_clip_path;
  169. #endif
  170.  
  171. /*
  172.  * Define the driver procedure for text.  This procedure must allocate
  173.  * the enumerator (see gxtext.h) and initialize the procs and rc members.
  174.  */
  175. #define dev_t_proc_text_begin(proc, dev_t)\
  176.   int proc(P9(dev_t *dev,\
  177.     gs_imager_state *pis,\
  178.     const gs_text_params_t *text,\
  179.     gs_font *font,\
  180.     gx_path *path,            /* unless DO_NONE */\
  181.     const gx_device_color *pdcolor,    /* if DO_DRAW */\
  182.     const gx_clip_path *pcpath,        /* if DO_DRAW */\
  183.     gs_memory_t *memory,\
  184.     gs_text_enum_t **ppte))
  185. #define dev_proc_text_begin(proc)\
  186.   dev_t_proc_text_begin(proc, gx_device)
  187.  
  188. /*
  189.  * Begin processing text.  This calls the device procedure, and also
  190.  * initializes the common parts of the enumerator.
  191.  */
  192. dev_proc_text_begin(gx_device_text_begin);
  193.  
  194. /* Begin processing text with a graphics state. */
  195. #ifndef gs_state_DEFINED
  196. #  define gs_state_DEFINED
  197. typedef struct gs_state_s gs_state;
  198. #endif
  199. int gs_text_begin(P4(gs_state * pgs, const gs_text_params_t * text,
  200.              gs_memory_t * mem, gs_text_enum_t ** ppenum));
  201.  
  202. /* Begin the PostScript-equivalent text operators. */
  203. int
  204.     gs_show_begin(P5(gs_state *, const byte *, uint,
  205.              gs_memory_t *, gs_text_enum_t **)),
  206.     gs_ashow_begin(P7(gs_state *, floatp, floatp, const byte *, uint,
  207.               gs_memory_t *, gs_text_enum_t **)),
  208.     gs_widthshow_begin(P8(gs_state *, floatp, floatp, gs_char,
  209.               const byte *, uint,
  210.               gs_memory_t *, gs_text_enum_t **)),
  211.     gs_awidthshow_begin(P10(gs_state *, floatp, floatp, gs_char,
  212.                 floatp, floatp, const byte *, uint,
  213.                 gs_memory_t *, gs_text_enum_t **)),
  214.     gs_kshow_begin(P5(gs_state *, const byte *, uint,
  215.               gs_memory_t *, gs_text_enum_t **)),
  216.     gs_xyshow_begin(P8(gs_state *, const byte *, uint,
  217.                const float *, const float *, uint,
  218.                gs_memory_t *, gs_text_enum_t **)),
  219.     gs_glyphshow_begin(P4(gs_state *, gs_glyph,
  220.               gs_memory_t *, gs_text_enum_t **)),
  221.     gs_cshow_begin(P5(gs_state *, const byte *, uint,
  222.               gs_memory_t *, gs_text_enum_t **)),
  223.     gs_stringwidth_begin(P5(gs_state *, const byte *, uint,
  224.                 gs_memory_t *, gs_text_enum_t **)),
  225.     gs_charpath_begin(P6(gs_state *, const byte *, uint, bool,
  226.              gs_memory_t *, gs_text_enum_t **)),
  227.     gs_glyphpath_begin(P5(gs_state *, gs_glyph, bool,
  228.               gs_memory_t *, gs_text_enum_t **)),
  229.     gs_glyphwidth_begin(P4(gs_state *, gs_glyph,
  230.                gs_memory_t *, gs_text_enum_t **)),
  231.     gs_charboxpath_begin(P6(gs_state *, const byte *, uint, bool,
  232.                 gs_memory_t *, gs_text_enum_t **));
  233.  
  234. /*
  235.  * Restart text processing with new parameters.
  236.  */
  237. int gs_text_restart(P2(gs_text_enum_t *pte, const gs_text_params_t *text));
  238.  
  239. /*
  240.  * Resync text processing with new parameters and string position.
  241.  */
  242. int gs_text_resync(P2(gs_text_enum_t *pte, const gs_text_enum_t *pfrom));
  243.  
  244. /*
  245.  * Define the possible return values from gs_text_process.  The client
  246.  * should call text_process until it returns 0 (successful completion) or a
  247.  * negative (error) value.
  248.  */
  249.  
  250.     /*
  251.      * The client must render a character: obtain the code from
  252.      * gs_text_current_char/glyph, do whatever is necessary, and then
  253.      * call gs_text_process again.
  254.      */
  255. #define TEXT_PROCESS_RENDER 1
  256.  
  257.     /*
  258.      * The client has asked to intervene between characters.
  259.      * Obtain the current and next codes from gs_text_current_char/glyph
  260.      * and gs_text_next_char, do whatever is necessary, and then
  261.      * call gs_text_process again.
  262.      */
  263. #define TEXT_PROCESS_INTERVENE 2
  264.  
  265. /* Process text after 'begin'. */
  266. int gs_text_process(P1(gs_text_enum_t *pte));
  267.  
  268. /* Access elements of the enumerator. */
  269. gs_font *gs_text_current_font(P1(const gs_text_enum_t *pte));
  270. gs_char gs_text_current_char(P1(const gs_text_enum_t *pte));
  271. gs_char gs_text_next_char(P1(const gs_text_enum_t *pte));
  272. gs_glyph gs_text_current_glyph(P1(const gs_text_enum_t *pte));
  273. int gs_text_total_width(P2(const gs_text_enum_t *pte, gs_point *pwidth));
  274.  
  275. /*
  276.  * After the implementation returned TEXT_PROCESS_RENDER, determine
  277.  * whether it needs the entire character description, or only the width
  278.  * (escapement).
  279.  */
  280. bool gs_text_is_width_only(P1(const gs_text_enum_t *pte));
  281.  
  282. /*
  283.  * Return the width of the current character (in user space coordinates).
  284.  */
  285. int gs_text_current_width(P2(const gs_text_enum_t *pte, gs_point *pwidth));
  286.  
  287. /*
  288.  * Set text metrics and optionally enable caching.  Return 1 iff the
  289.  * cache device was just installed.
  290.  */
  291. typedef enum {
  292.     TEXT_SET_CHAR_WIDTH,    /* wx wy */
  293.     TEXT_SET_CACHE_DEVICE,    /* wx wy llx lly urx ury */
  294.     TEXT_SET_CACHE_DEVICE2    /* w0x w0y llx lly urx ury w1x w1y vx vy */
  295. } gs_text_cache_control_t;
  296. int
  297.     gs_text_set_cache(P3(gs_text_enum_t *pte, const double *values,
  298.              gs_text_cache_control_t control)),
  299.     gs_text_setcharwidth(P2(gs_text_enum_t *pte, const double wxy[2])),
  300.     gs_text_setcachedevice(P2(gs_text_enum_t *pte, const double wbox[6])),
  301.     gs_text_setcachedevice2(P2(gs_text_enum_t *pte, const double wbox2[10]));
  302.  
  303. /* Retry processing of the last character. */
  304. int gs_text_retry(P1(gs_text_enum_t *pte));
  305.  
  306. /* Release the text processing structures. */
  307. void gs_text_release(P2(gs_text_enum_t *pte, client_name_t cname));
  308.  
  309. #endif /* gstext_INCLUDED */
  310.